package com.java.collection;

import java.util.HashMap;
import java.util.Map;

public class CarHashMapDemo1 {
    public static void main(String[] args) {
        // 汽车集合，key司机名字 value汽车对象
        Map<Driver, Car> cars = new HashMap<>();

        // 添加数据
        Driver driver1 = new Driver("张三",20,"男");
        Driver driver2 = new Driver("李四",21,"男");
        Driver driver3 = new Driver("王五",22,"男");
        Driver driver4 = new Driver("赵六",23,"男");

        cars.put(driver1,new Car("01","奔驰",100000,"黑色"));
        cars.put(driver2,new Car("02","宝马",200000,"白色"));
        cars.put(driver3,new Car("03"," Audi",300000,"蓝色"));
        cars.put(driver4,new Car("04","法拉利",400000,"红色"));

        //new新的对象，内存地址不同，无法找到value
        Car car = cars.get(new Driver("王五",22,"男"));
        System.out.println("找到汽车"+car);
        Car car1 = cars.get(new Driver("赵六",23,"男"));
        System.out.println("找到汽车"+car1);
    }
}
